from django.db import models
from User.models import User


# Create your models here.
from utils.dateFun import getNowTimeStamp


class Medicine(models.Model):
    """
    药品表
    """
    id = models.CharField(verbose_name='药品ID', max_length=255, null=False, primary_key=True)
    name = models.CharField(verbose_name='药品名称', max_length=255, null=False)
    startTimeStamp = models.CharField(verbose_name='开始时间', max_length=255, null=False)
    endTimeStamp = models.CharField(verbose_name='结束时间', max_length=255, null=False)
    dosage = models.CharField(verbose_name='用药剂量', max_length=255, null=False)
    status = models.BooleanField(verbose_name='是否开启提醒', null=True, default=True)
    creatTimeStamp = models.CharField(verbose_name='创建时间', max_length=255, null=True, default=getNowTimeStamp())
    user = models.ForeignKey(verbose_name='用户ID', to=User, to_field='uid', on_delete=models.CASCADE)

    class Meta:
        db_table = 'Medicine'
        verbose_name = '药品表'


class ReminderItem(models.Model):
    """
    用药提醒项表
    """
    id = models.CharField(verbose_name='用药提醒项ID', max_length=255, null=False, primary_key=True)
    timeStamp = models.CharField(verbose_name='服用时间', max_length=255, null=False)
    creatTimeStamp = models.CharField(verbose_name='创建时间', max_length=255, null=True, default=getNowTimeStamp())
    medicine = models.ForeignKey(verbose_name='药品ID', to=Medicine, to_field='id', on_delete=models.CASCADE)

    class Meta:
        db_table = 'ReminderItem'
        verbose_name = '用药提醒项表'


class FinishedRecord(models.Model):
    """
    服药记录表
    """
    id = models.CharField(verbose_name='用药提醒项ID', max_length=255, null=False, primary_key=True)
    timeStamp = models.CharField(verbose_name='服用时间', max_length=255, null=False)
    creatTimeStamp = models.CharField(verbose_name='创建时间', max_length=255, null=True, default=getNowTimeStamp())
    reminderItem = models.ForeignKey(verbose_name='用药提醒项ID', to=ReminderItem, to_field='id', on_delete=models.CASCADE)

    class Meta:
        db_table = 'FinishedRecord'
        verbose_name = '服药记录表'
